{include file="./header"  title="权限编辑"/}
<div class="container-fluid">
<form action="" method="post" enctype="multipart/form-data">
    <table class="table table-hover">
  <thead>
  <tr>
    <td>名称</td>
    <td>编辑</td>
    <td>说明</td>
  </tr>
  </thead>
  
  
  
  <tr class="form-group">
    <td><label for="pid">上级权限</label></td>
    <td class="row">
    	<div class="col-md-6" >
        <select class="form-control pid" id="pid_1" >
          <option>请选择</option>
          {foreach name="list" item="val"}
          <option value="{$val.id}">{$val.name}</option>
          {/foreach}
        </select>
        </div>
        <div class="col-md-6">
        <select class="form-control pid" id="pid_2" >
          <option value="0">请选择</option>
        </select>
        </div>
    </td>
    <td>权限名称</td>
  </tr>
  
  <tr class="form-group">
    <td><label for="name">名称</label></td>
    <td><input name="name" type="text" class="form-control" id="name" /></td>
    <td>权限名称</td>
  </tr>
  
  <tr class="form-group">
    <td><label for="value">参数</label></td>
    <td><input name="value" type="text" class="form-control" id="value" /></td>
    <td>&nbsp;</td>
  </tr>
  
  <tr class="form-group">
    <td><label for="status">状态</label></td>
    <td>
        <input type="radio" name="status" value="1">开启
        <input name="status" type="radio" value="0" checked="checked">关闭
        
    </td>
    <td>&nbsp;</td>
  </tr>
  
  <tr class="form-group">
    <td>
    <input type="submit" class="btn btn-primary" id="button" value="提交" />
    <button type="button" onClick="javascript:history.back(-1);" class="btn btn-primary">返回</button>
    </td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
    </form>
</div>

<script>
$(function(){
	
	//自动选取那个为上机菜单
	$(".pid").change(function(e){
		$(".pid").attr('name',null);
		$(this).attr('name','pid');	
	});
	
	$("#pid_1").change(function(e) {
		
		var pid = $(this).val();
		var html = '<option value="0">顶级</option>';
		if(pid > 0){
			$.getJSON("{:url('action_ajax')}?pid="+pid,function(data){
				var data = data.data;
				
				for(i=0;i<data.length;i++){
				  html += "<option value='"+data[i]['id']+"' >"+data[i]['name']+"</option>";
				}
				$("#pid_2").html(html);
			});
		}else{
			var html = '<option value="0">请选择</option>';
			$("#pid_2").html(html);
		}
    });
	
	
});
</script>
{include file="./footer" /}
